package com.guigu.dh.common.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * 获取当前用户信息工具类
 *
 * @author DengHao
 * @date 2022-03-12
 */
public class AuthContextHolder {
    /**
     * 获取当前用户id
     *
     * @param request
     * @return
     */
    public static Long getId(HttpServletRequest request) {
        //从header获取token
        String token = request.getHeader("token");
        //jwt从token获取phone
        return JWTUtil.getTokenId(token);
    }

    /**
     * 获取当前用户phone
     *
     * @param request
     * @return
     */
    public static String getPhone(HttpServletRequest request) {
        //从header获取token
        String token = request.getHeader("token");
        //jwt从token获取phone
        return JWTUtil.getTokenPhone(token);
    }

    /**
     * 获取当前用户名称
     *
     * @param request
     * @return
     */
    public static String getUserName(HttpServletRequest request) {
        //从header获取token
        String token = request.getHeader("token");
        //jwt从token获取name
        return JWTUtil.getTokenName(token);
    }
}
